package vip.xiaonuo.miniapp.api.miniapp.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import vip.xiaonuo.core.context.constant.ConstantContextHolder;

@Component
public class WxMaConfiguration {

    public WxMaService getMaService() {
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        String wx_appid = ConstantContextHolder.getSysConfig("WX_APPID", String.class, true);
        String wx_secret = ConstantContextHolder.getSysConfig("WX_SECRET", String.class, true);
        config.setAppid(wx_appid);
        config.setSecret(wx_secret);
        config.setMsgDataFormat("JSON");
        WxMaService wxMaService = new WxMaServiceImpl();
        wxMaService.setWxMaConfig(config);
        return wxMaService;
    }
}
